import React from 'react'
import PropTypes from 'prop-types'
import { message, Tag } from 'antd'
import {ShowDiv} from './style'
import {View} from './view'
import Example from './animate'
import {connect} from 'react-redux'
import {withRouter} from 'react-router-dom'
import Time from '../deng/time'
import Model from './model'
function Show (props) {
  if(props.show) {
    return <div>显示</div>
  } else {
    return <div>隐藏</div>
  }
}
class Shop extends React.PureComponent
{
  static all = {
    age: 12
  }
  constructor(){
    super()
    this.state = {
      age: 13,
      sex: 1,
      show: true,
      time: null,
    }
  }
  time = ()=>{
    let time = setTimeout(()=>{
      this.setState({
        show: false
      })
      this.setState((state)=>{
        if(state.show === false) {
          console.log('修改成功')
          message.info({
            content: '修改成功'
          })
        }
      })
    },2000)
    this.setState({
      time: time
    })
    
  }
  shou = ()=>{
    console.log(this)
    this.props.history.push({pathname: '/',state:{name:'shop'},hash:'1',search:'1'})
    // this.props.history.push(path,state)
  }
  componentDidMount () {
    console.log(this)
    this.time()
  }
  componentWillUnmount () {
    console.log(this.state.time)
    clearTimeout(this.state.time)
  }
  render () {
    return <div>
      <Time></Time>
      <Model></Model>
      <Tag onClick={this.shou}>首页</Tag>
      {this.props.name}{Shop.all.age}
      {/* <Tag>{this.state.age}</Tag>
      <Tag>{this.state.sex}</Tag> */}
      <span>{this.state.sex}</span>
      <Show show={this.state.show}></Show>
      <ShowDiv>
        <View></View>
      </ShowDiv>
      <Tag>123</Tag>
      <Example/>
    </div>
  }
}
Shop.propTypes = {
  name:PropTypes.string.isRequired
}
const dis = dispatch => {
  return {
      onTodoClick: () => {
          dispatch(addToCart(1, 2, 3))

      },
      onOpen: (a) => {
          dispatch(open(a))
      }
  }
}
const ste = (state) => {
  return {
      product: state.product,
  }
}
export default connect(ste, dis)(withRouter(Shop));
